<!--上架记录查询-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      v-if="initTemplate"
      ref="multipleTable"
      :dynamicButtons="tableButtons"
      :dynamicComponents="tableComponents"
      :dynamicApiConfig="apiConfig"
      :dynamicTableCols="tableCols"
      :dynamicFormFields="formField"
      :dynamicIsShowSelect="false"
      :dynamicIsColumnDrop="true"
    >
      <template slot="IS_URGENCY_STR" slot-scope="scope">
        <el-tag type="success" v-if="scope.row.IS_URGENCY_STR==='普通'">{{scope.row.IS_URGENCY_STR}}</el-tag>
        <el-tag type="danger" v-else>{{scope.row.IS_URGENCY_STR}}</el-tag>
      </template>
      <template slot="IS_RETROSPECT_STR" slot-scope="scope">
        <el-tag
          type="success"
          v-if="scope.row.IS_RETROSPECT_STR==='不追溯'"
        >{{scope.row.IS_RETROSPECT_STR}}</el-tag>
        <el-tag type="danger" v-else>{{scope.row.IS_RETROSPECT_STR}}</el-tag>
      </template>
    </one-table-template>
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from "@/components/mixins/oneTableWithViewTemplateMixins";
import { wmsApis } from "@/api/wms/inStock/api";
import OneTableTemplate from "@/components/wms/templates/oneTable";
import request from "@/utils/request";
export default {
  name: "stockQuery",
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],
  components: {
    OneTableTemplate
  },
  created() {
    // if (this.$route.query != null) {
    //   // 判断传入query参数，初始化数据
    //   if (this.$route.query.pageId != null && this.$route.query.pageId !== "") {
    //     this.formField.pageId = this.$route.query.pageId;
    //     this.formField.pageName = this.$route.query.pageName;
    //   }
    // }
    this.querySelect();
  },
  data() {
    return {
      // 网格查询API配置对象
      curPopupsVisible: false,
      curPopupsKey: "",
      apiConfig: wmsApis.queryPuton,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.queryTable(),
          name: "search",
          position: "right",
          text: "查询" //"查询"
        },
        {
          compKey: "btnKey3",
          type: "",
          size: "small",
          name: "reset",
          position: "right",
          clickEvent: () => this.reset(),
          text: "重置" //"重置"
        },
        {
          compKey: "btnKey4",
          type: "",
          size: "small",
          clickEvent: () => this.export(),
          name: "export",
          position: "right",
          text: "导出" //"导出"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "compKey1",
          labelName: "仓库名称",
          codeField: "WAREHOUSE_IDS",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          isMul: true,
          options: []
        },
        {
          compKey: "compKey2",
          labelName: "到货类型",
          codeField: "ARRIVAL_TYPE",
          lookuptype: "PRO0004",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          isMul: false,
          options: []
        },
        {
          compKey: "compKey3",
          labelName: "上架日期",
          codeField: "LAST_UPDATED_DATE_START",
          component: () => import("@/components/wms/datePicker/andtDatePicker"),
          type: "date",
          isMust: true
        },
        {
          compKey: "compKey4",
          labelName: "追溯标识",
          codeField: "IS_RETROSPECT",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          isMul: false,
          options: [
            {
              label: "不追溯",
              value: "0"
            },
            {
              label: "要追溯",
              value: "1"
            }
          ]
        },
        {
          compKey: "compKey5",
          labelName: "备件编号",
          codeField: "PART_NO",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey6",
          labelName: "备件名称",
          codeField: "PART_NAME",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey7",
          labelName: "合作伙伴编号",
          textField: "SUPPLIER_CODE",
          codeField: "SUPPLIER_CODE",
          component: () =>
            import("@/components/wms/wmsEjectWindows/wmsContractInfo"),
          type: "propus",
          isMust: true,
          isMul: false,
          returnCodeField: "SUPPLIER_CODE",
          returnTextField: "SUPPLIER_CODE"
        },
        {
          compKey: "compKey8",
          labelName: "合作伙伴名称",
          codeField: "PARTNER_SHORT_NAME",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          disabled: true
        },
        {
          compKey: "compKey9",
          labelName: "紧急标识",
          codeField: "IS_URGENCY",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          isMul: false,
          options: [
            {
              label: "普通",
              value: "0"
            },
            {
              label: "紧急",
              value: "1"
            }
          ]
        },
        {
          compKey: "compKey10",
          labelName: "收货单号",
          codeField: "RECEIVE_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey11",
          labelName: "到货单号",
          codeField: "ARRIVAL_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        },
        {
          compKey: "compKey12",
          labelName: "关联单号",
          codeField: "RELATION_CODE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true
        }
      ],
      // 动态生成网格列
      tableCols: [
        {
          prop: "PUTON_CODE",
          label: "上架卡号",
          align: "center",
          width: "120px"
        },
        {
          prop: "IS_URGENCY_STR",
          label: "紧急标识",
          align: "center",
          width: "100px",
          isSlot: true
        },
        {
          prop: "PART_NO",
          label: "备件编号",
          align: "center",
          width: "100px"
        },
        {
          prop: "PART_NAME",
          label: "备件名称",
          align: "center",
          width: "100px"
        },
        {
          prop: "RECEIVE_QTY",
          label: "任务数量",
          align: "center"
        },
        {
          prop: "PUTON_QTY",
          label: "本次上架数量",
          align: "center"
        },
        {
          prop: "ERROR_QTY",
          label: "异常数量",
          align: "center"
        },
        {
          prop: "IS_RETROSPECT_STR",
          label: "追溯标识",
          align: "center",
          width: "100px",
          isSlot: true
        },
        {
          prop: "AREA_NAME",
          label: "库区",
          align: "center",
          width: "100px"
        },
        {
          prop: "PLACE_CODE",
          label: "库位",
          align: "center",
          width: "100px"
        },
        {
          prop: "LAST_UPDATED_DATE_NEW",
          label: "上架时间",
          align: "center",
          width: "140px"
        },
        {
          prop: "EMP_NAME",
          label: "操作人",
          align: "center",
          width: "100px"
        },
        {
          prop: "REMARK",
          label: "备注",
          align: "center",
          width: "100px"
        },
        {
          prop: "RECEIVE_CODE",
          label: "收货单号",
          align: "center",
          width: "140px"
        },
        {
          prop: "ARRIVAL_CODE",
          label: "到货单号",
          align: "center",
          width: "140px"
        },
        {
          prop: "RELATION_CODE",
          label: "关联单号",
          align: "center",
          width: "140px"
        },
        {
          prop: "ARRIVAL_TYPE_NAME",
          label: "收货类型",
          align: "center",
          width: "100px"
        },
        {
          prop: "PARTNER_TYPE_NAME",
          label: "伙伴类别",
          align: "center",
          width: "100px"
        },
        {
          prop: "SUPPLIER_CODE",
          label: "伙伴编号",
          align: "center",
          width: "100px"
        },
        {
          prop: "PARTNER_SHORT_NAME",
          label: "伙伴简称",
          align: "center",
          width: "100px"
        },
        {
          prop: "WAREHOUSE_NAME",
          label: "仓库名称",
          align: "center",
          width: "100px"
        }
      ],
      //表单查询数据
      formField: {
        WAREHOUSE_IDS: "",
        WAREHOUSE_IDS_NEW: "",
        ARRIVAL_TYPE: "",
        LAST_UPDATED_DATE_START: "",
        IS_RETROSPECT: "",
        PART_NO: "",
        PART_NAME: "",
        SUPPLIER_CODE: "",
        PARTNER_SHORT_NAME: "",
        IS_URGENCY: "",
        RECEIVE_CODE: "",
        ARRIVAL_CODE: "",
        RELATION_CODE: ""
      },
      unFormField: {},
      // 控制初始化页面
      initTemplate: false
    };
  },
  methods: {
    querySelect() {
      // const that = this.$refs[this.tableRef];
      request({
        url: "/mp/wm/vl/basedata/warehouseuser/queryUserByWHBox.do",
        method: "post",
        data: {
          IS_ENABLE: "1"
        }
      }).then(res => {
        if (res.listRow && res.listRow.length > 0) {
          res.listRow.map(item => {
            this.formField.WAREHOUSE_IDS_NEW += item.WAREHOUSE_ID + ",";
            this.tableComponents[0].options.push({
              label: item.WAREHOUSE_NAME,
              value: item.WAREHOUSE_ID
            });
          });
          this.formField.WAREHOUSE_IDS_NEW = this.formField.WAREHOUSE_IDS_NEW.substr(
            0,
            this.formField.WAREHOUSE_IDS_NEW.length - 1
          );
          this.formField.WAREHOUSE_IDS = res.listRow[0].WAREHOUSE_ID;
        }
        this.initTemplate = true;
        this.$nextTick(() => {
          this.queryTable();
        });
      });
      request({
        url: "/mp/wm/vl/warehouse/arrival/queryArrivalType.do",
        method: "post",
        data: {}
      }).then(res => {
        if (res.listRow && res.listRow.length > 0) {
          res.listRow.map(item => {
            this.tableComponents[1].options.push({
              label: item.ARRIVAL_NAME,
              value: item.ARRIVAL_TYPE
            });
          });
        }
      });
    },
    export() {
      const exportLoading = this.$loading({
        lock: true,
        text: "正在导出...",
        // spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
        fullscreen: true
      });
      request({
        url: "/mp/wm/vl/warehouse/instorage/exportPuton.do",
        method: "post",
        headers: {
          "Cache-Control": "no-cache, no-store,max-age=0, must-revalidate",
          Pragma: "no-cache",
          Expires: "0",
          "Content-Type": "application/json;charset=UTF-8"
        },
        responseType: "blob",
        data: this.formField
      })
        .then(response => {
          exportLoading.close();
          let blob = new Blob([response], { type: "application/vnd.ms-excel" }); // 这里表示xmlx类型
          let downloadElement = document.createElement("a");
          let href = window.URL.createObjectURL(blob); // 创建下载的链接
          downloadElement.href = href;
          downloadElement.download = "上架查询导出.xls"; // 下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); // 点击下载
          document.body.removeChild(downloadElement); // 下载完成移除元素
          window.URL.revokeObjectURL(href); // 释放掉blob对象
        })
        .catch(err => {
          exportLoading.close();
          console.log(err);
        });
    }
  }
};
</script>
